# -*-coding:utf-8 -*-
"""
# File       : main.py
# Time       ：2022/3/21 11:05
# Author     ：Coco
# version    ：python 3.7
"""
import sys
from PyQt5.QtCore import Qt, QVersionNumber
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QFont
from PyQt5 import QtGui, QtWidgets, QtCore
from gui.driver.main_driver import Driver
import time
import cgitb

cgitb.enable(format='text', logdir="logs/error_file")  # error output 191014

if __name__ == '__main__':

    v_compare = QVersionNumber(5, 6, 0)
    v_current, _ = QVersionNumber.fromString(QtCore.QT_VERSION_STR)  # 获取当前Qt版本
    # 设置程序中的字体大小
    app = QApplication(sys.argv)
    font = QFont("宋体")
    point_size = font.pointSize()
    font.setPointSize(12)
    app.setFont(font)
    # Create and display the splash screen
    splash_pix = QtGui.QPixmap('static/style_sheet/icons/welcome.png')
    splash = QtWidgets.QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
    splash.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
    splash.setEnabled(False)
    # adding progress bar
    progressBar = QtWidgets.QProgressBar(splash)
    progressBar.setTextVisible(False)
    progressBar.setMaximum(100)
    progressBar.setGeometry(0, splash_pix.height() - 10, splash_pix.width(), 10)
    splash.show()
    for i in range(1, 100):
        progressBar.setValue(i)
        t = time.time()
        while time.time() < t + 0.001:
            # 设置进程，启动加载页面时可以进行其他操作而不会卡死
            app.processEvents()
    window = Driver()
    window.show()
    splash.finish(window)
    sys.exit(app.exec())
